<?php

namespace App\Http\Controllers;

use App\Models\Zan;
use Illuminate\Http\Request;

class ZanController extends Controller
{
    //
    public function index(Request $request)
    {

    }

    public function store(Request $request)
    {
        $user = $request->user();
        $cover_id = $request->post('cover_id');

        $coll = (new Zan)->zanOrCancel($cover_id, $user->id);

        if (!$coll) return $this->response([],'服务端异常',500);

        else return $this->response([],'成功');
    }

    public function is_zan(Request $request)
    {
        $cover_id = $request->get('cover_id');

        $user = $request->user();

        $isZan = Zan::query()->where('cover_id', $cover_id)
            ->where('user_id', $user->id)
            ->where('state', 1)
            ->exists();

        return $this->response(['isZan' => $isZan]);
    }
}
